import java.util.*;

public class Main {
    // 最长公共子序列
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String s1 = in.next();
            String s2 = in.next();

            int s1Len = s1.length();
            int s2Len = s2.length();
            int[][] arr = new int[s1Len + 1][s2Len + 1];

            for (int i = 1; i <= s1Len; i++) {
                for (int j = 1; j <= s2Len; j++) {
                    if (s1.charAt(i - 1) == s2.charAt(j - 1)) {
                        arr[i][j] = arr[i - 1][j - 1] + 1;
                    } else {
                        arr[i][j] = Math.max(arr[i - 1][j], arr[i][j - 1]);
                    }
                }
            }
            System.out.println(arr[s1Len][s2Len]);
        }
    }
}
